use std::collections::HashMap;

// 结构体定义
#[derive(Debug)]
struct Student {
    name: String,
    email: String,
    age: u32,
}

// 元组结构定义
// 与结构体相比，没有属性名
#[derive(Debug)]
struct Grades(char, f32);

// 枚举定义
#[derive(Debug)]
enum Gender {
    Male,
    Female,
    Unknown,
}

// 枚举中的可选项可以是不同的类型
#[derive(Debug)]
enum SomeType {
    IntegerVariant(i32),
    StringVarient(String),
}

fn main() {
    /**************** 结构体，元组，枚举 ********************/
    // 实例化结构体
    let mut s = Student {
        name: String::from("Charles"),
        email: String::from("z@gmail.com"),
        age: 20,
    };
    /*
     * let mut s = Student {};
     * 无法初始化空结构体
     */

    // 修改结构体
    s.age = 26;
    println!("name: {}, email: {}, age: {}", s.name, s.email, s.age);


    // 实例化元组结构
    let mut tu = Grades('A', 86.5);

    // 修改元组
    tu.1 += 1.0;

    println!("Rank: {}, Grade: {}", tu.0, tu.1);

    // 枚举的使用1
    let gender = Gender::Male;
    match gender {
        Gender::Male => {
            println!("male");
        },
        Gender::Female => {
            println!("female");
        },
        Gender::Unknown => {
            println!("unknown");
        }
    };

    // 枚举的使用2

    let sometype1 = SomeType::IntegerVariant(5);
    let sometype2 = SomeType::StringVarient(String::from("variant"));
    println!("1: {:#?}", sometype1);
    println!("2: {:#?}", sometype2);


    /****************集合类型: 数组, vector, HashMap****************************/
    // 数组
    let days = ["一", "二", "三", "四", "五", "六", "日"];
    let bytes = [0; 5]; // 长度为5，元素全0
    println!("days[0] = {}", days[0]);
    println!("bytes[0] = {}", bytes[0]);

    // vector
    let mut names = vec!["Alice", "Bob", "Cathy"];
    names.push("Dasy");
    names.push("Elsa");
    println!("names: {:?}", names);
    println!("poped: {:?}", names.pop());
    println!("names: {:?}", names);
    let mut fruits = Vec::new();
    fruits.push("Apple");
    fruits.push("Banana");
    println!("fruits: {:?}", fruits);

    // HashMap
    let mut reviews: HashMap<String,String> = HashMap::new();

    // 插入键值对
    reviews.insert(String::from("Harry Potter"), String::from("Very good"));
    reviews.insert(String::from("Whatever"), String::from("not very good"));

    // 删除键值对
    reviews.remove("Whatever");
    println!("review of HP: {:?}", reviews.get("Harry Potter"));
    println!("review of HP: {:?}", reviews.get("Whatever"));

}
